<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"  %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

<STYLE type=text/css>
TD {FONT-SIZE: 10.8pt}
BODY {FONT-SIZE: 20.8pt}
BUTTON {WIDTH: 5em}
</STYLE>
<SCRIPT LANGUAGE=JAVASCRIPT SRC="dialog.js"></SCRIPT>

<SCRIPT language=JavaScript>


var sAction = URLParams['action'] ;

var sTitle = "";
var color = "" ;
var oSelection;
var oControl;
var sRangeType;

switch (sAction) {
	case "forecolor":
		sTitle = "<bean:message bundle='webEditor'  bundle="webEditor"  key='webEditor.FontFrontColor' />";
		oSelection = dialogArguments.eWebEditor.document.selection.createRange();
		color = oSelection.queryCommandValue("ForeColor");
		if (color) color = N2Color(color);
		break;
	case "backcolor":
		sTitle = "<bean:message bundle='webEditor'  bundle="webEditor"  key='webEditor.FontBackColor' />";
		oSelection = dialogArguments.eWebEditor.document.selection.createRange();
		color = oSelection.queryCommandValue("BackColor");
		if (color) color = N2Color(color);
		break;
	case "bgcolor":
		sTitle = "<bean:message bundle='webEditor'  bundle="webEditor"  key='webEditor.ObjectBackColor' />";
		oSelection = dialogArguments.eWebEditor.document.selection.createRange();
		sRangeType = dialogArguments.eWebEditor.document.selection.type;
		if (sRangeType == "Control") {
			oControl = GetControl(oSelection, "TABLE");
		}else{
			oControl = GetParent(oSelection.parentElement());
		}
		if (oControl) {
			switch(oControl.tagName){
			case "TD":
				sTitle += " - <bean:message bundle='webEditor'  bundle="webEditor"  key='webEditor.Cell' />";
				break;
			case "TR":
			case "TH":
				sTitle += " - <bean:message bundle='webEditor'  bundle="webEditor"  key='webEditor.TableRow' />";
				break;
			default:
				sTitle += " - <bean:message bundle='webEditor'  bundle="webEditor"  key='webEditor.Table' />";
				break;
			}
			color = oControl.bgColor;
		}else{
			sTitle += " -<bean:message bundle='webEditor'  bundle="webEditor"  key='webEditor.Page' />";
		}
		break;
	default:
		if (URLParams['color']){
			color = decodeURIComponent(URLParams['color']) ;
		}
		break;
}

document.write("<TITLE><bean:message bundle='webEditor'  bundle="webEditor"  key='webEditor.SelectColr' />(" + sTitle + ")</TITLE>");



if (!color) color = "#000000";

function GetParent(obj){
	while(obj!=null && obj.tagName!="TD" && obj.tagName!="TR" && obj.tagName!="TH" && obj.tagName!="TABLE")
		obj=obj.parentElement;
	return obj;
}


function GetControl(obj, sTag){
	obj=obj.item(0);
	if (obj.tagName==sTag){
		return obj;
	}
	return null;
}


function N2Color(s_Color){
	s_Color = s_Color.toString(16);
	switch (s_Color.length) {
	case 1:
		s_Color = "0" + s_Color + "0000";
		break;
	case 2:
		s_Color = s_Color + "0000";
		break;
	case 3:
		s_Color = s_Color.substring(1,3) + "0" + s_Color.substring(0,1) + "00" ;
		break;
	case 4:
		s_Color = s_Color.substring(2,4) + s_Color.substring(0,2) + "00" ;
		break;
	case 5:
		s_Color = s_Color.substring(3,5) + s_Color.substring(1,3) + "0" + s_Color.substring(0,1) ;
		break;
	case 6:
		s_Color = s_Color.substring(4,6) + s_Color.substring(2,4) + s_Color.substring(0,2) ;
		break;
	default:
		s_Color = "";
	}
	return '#' + s_Color;
}


function InitDocument(){
	ShowColor.bgColor = color;
	RGB.innerHTML = color;
	SelColor.value = color;
}


var SelRGB = color;
var DrRGB = '';
var SelGRAY = '120';

var hexch = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');

function ToHex(n) {
	var h, l;

	n = Math.round(n);
	l = n % 16;
	h = Math.floor((n / 16)) % 16;
	return (hexch[h] + hexch[l]);
}

function DoColor(c, l){
	var r, g, b;

	r = '0x' + c.substring(1, 3);
	g = '0x' + c.substring(3, 5);
	b = '0x' + c.substring(5, 7);

	if(l > 120){
		l = l - 120;

		r = (r * (120 - l) + 255 * l) / 120;
		g = (g * (120 - l) + 255 * l) / 120;
		b = (b * (120 - l) + 255 * l) / 120;
	}else{
		r = (r * l) / 120;
		g = (g * l) / 120;
		b = (b * l) / 120;
	}

	return '#' + ToHex(r) + ToHex(g) + ToHex(b);
}

function EndColor(){
	var i;

	if(DrRGB != SelRGB){
		DrRGB = SelRGB;
		for(i = 0; i <= 30; i ++)
		GrayTable.rows(i).bgColor = DoColor(SelRGB, 240 - i * 8);
	}

	SelColor.value = DoColor(RGB.innerText, GRAY.innerText);
	ShowColor.bgColor = SelColor.value;
}
</SCRIPT>

<SCRIPT event=onclick for=ColorTable language=JavaScript>
	SelRGB = event.srcElement.bgColor;
	EndColor();
</SCRIPT>

<SCRIPT event=onmouseover for=ColorTable language=JavaScript>
	RGB.innerText = event.srcElement.bgColor;
	EndColor();
</SCRIPT>

<SCRIPT event=onmouseout for=ColorTable language=JavaScript>
	RGB.innerText = SelRGB;
	EndColor();
</SCRIPT>

<SCRIPT event=onclick for=GrayTable language=JavaScript>
	SelGRAY = event.srcElement.title;
	EndColor();
</SCRIPT>

<SCRIPT event=onmouseover for=GrayTable language=JavaScript>
	GRAY.innerText = event.srcElement.title;
	EndColor();
</SCRIPT>

<SCRIPT event=onmouseout for=GrayTable language=JavaScript>
	GRAY.innerText = SelGRAY;
	EndColor();
</SCRIPT>

<SCRIPT event=onclick for=Ok language=JavaScript>
	color = SelColor.value;

	if (!IsColor(color)){
		alert('<bean:message bundle='webEditor'  bundle="webEditor"  key="webEditor.Color" />');
		return;
	}

		opener.document.getElementsByName(sAction)[0].value=color;
		/*
	switch (sAction) {

		case "color":
			opener.document.forms[0].color.value=color;
		    break;
		case "bgColor":
			opener.document.forms[0].bgColor.value=color;
		    break;

		case "style.borderColor":`
			opener.document.all("style.borderColor").value=color;
		    break;
        case "style.color":
			opener.document.all("style.color").value=color;
		    break;
        case "style.backColor":
			opener.document.all("fontStyle.backColor").value=color;
		    break;
        case "style.foreColor":
			opener.document.all("fontStyle.foreColor").value=color;
		    break;
        case "style.backImageUrl":
			opener.document.all("fontStyle.backImageUrl").value=color;
		    break;


	}
	*/

	window.close();
</SCRIPT>
<BODY bgColor=menu onload="InitDocument()">
<DIV align=center>
<CENTER>
<TABLE border=0 cellPadding=0 cellSpacing=10>
<TBODY>
<TR>
<TD>
<TABLE border=0 cellPadding=0 cellSpacing=0 id=ColorTable style="CURSOR: hand">
<SCRIPT language=JavaScript>
function wc(r, g, b, n){
	r = ((r * 16 + r) * 3 * (15 - n) + 0x80 * n) / 15;
	g = ((g * 16 + g) * 3 * (15 - n) + 0x80 * n) / 15;
	b = ((b * 16 + b) * 3 * (15 - n) + 0x80 * n) / 15;

	document.write('<TD BGCOLOR=#' + ToHex(r) + ToHex(g) + ToHex(b) + ' height=8 width=8></TD>');
}

var cnum = new Array(1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0);

for(i = 0; i < 16; i ++){
	document.write('<TR>');
	for(j = 0; j < 30; j ++){
		n1 = j % 5;
		n2 = Math.floor(j / 5) * 3;
		n3 = n2 + 3;

		wc((cnum[n3] * n1 + cnum[n2] * (5 - n1)),
		(cnum[n3 + 1] * n1 + cnum[n2 + 1] * (5 - n1)),
		(cnum[n3 + 2] * n1 + cnum[n2 + 2] * (5 - n1)), i);
	}

	document.writeln('</TR>');
}
</SCRIPT>

<TBODY></TBODY></TABLE></TD>
<TD>
<TABLE border=0 cellPadding=0 cellSpacing=0 id=GrayTable style="CURSOR: hand">
<SCRIPT language=JavaScript>
for(i = 255; i >= 0; i -= 8.5)
document.write('<TR BGCOLOR=#' + ToHex(i) + ToHex(i) + ToHex(i) + '><TD TITLE=' + Math.floor(i * 16 / 17) + ' height=4 width=20></TD></TR>');
</SCRIPT>

<TBODY></TBODY></TABLE></TD></TR></TBODY></TABLE></CENTER></DIV>
<DIV align=center>
<CENTER>
<TABLE border=0 cellPadding=0 cellSpacing=10>
<TBODY>
<TR>
<TD align=middle rowSpan=2><bean:message bundle='webEditor'  bundle="webEditor"  key="webEditor.TextColor.SelectColor" />
<TABLE border=1 cellPadding=0 cellSpacing=0 height=30 id=ShowColor width=40 bgcolor="">
<TBODY>
<TR>
<TD></TD></TR></TBODY></TABLE></TD>
<TD rowSpan=2><bean:message bundle='webEditor'  bundle="webEditor"  key="webEditor.TextColor.BaseColor" /><SPAN id=RGB></SPAN><BR><bean:message bundle='webEditor'  bundle="webEditor"  key="webEditor.TextColor.ColorHighlight" /> <SPAN
id=GRAY>120</SPAN><BR><bean:message bundle='webEditor'  bundle="webEditor"  key="webEditor.TextColor.Code" /> <INPUT id=SelColor size=7 value=""></TD>
<TD><BUTTON id=Ok type=submit><bean:message bundle='webEditor'  bundle="webEditor"  key="webEditor.Confirm" /></BUTTON></TD></TR>
<TR>
<TD><BUTTON onclick=window.close();><bean:message bundle='webEditor'  bundle="webEditor"  key="webEditor.Cancel" /></BUTTON></TD></TR></TBODY></TABLE></CENTER></DIV>
